/**
 * Created by ROGSTAR on 2016/11/29.
 */
require.config(window.jshead);
require(['jquery', 'highChart', 'navigator'], function ($, highcharts) {
    var linedatax = [];
    var linedatay = [];
    var linedatay2 = [];
    var linedatax2 = [];
    var pieDate1 = [];
    var pieDate = [];
    investment();
    function realnameState() {
        $.ajax({
            type: "POST",
            url: "/user/security/information",
            dataType: "json",
            success: function (data) {
                if (data.security.realnameStatus == 0) {
                    layer.alert('未进行实名认证，即将跳转至实名认证页面');
                    function jump() {
                        window.location.href = '/user/security/realname'
                    }
                    window.setTimeout(jump, 1500);
                }

            },
            error:function (data) {
                layer.alert('网络异常');
            }
        });
    };
    realnameState();
    //数字每三位增加一个逗号
    function threeNumber(num) {
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
            num = num.substring(0,num.length-(4*i+3))+','+
                num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + num + '.' + cents);
    }


    // //点击按钮切换视图
    // $('.anNiuYou').click(function(){
    //     $('.cheDaibao').hide();
    //     $('.wdFuli').show();
    // });
    // $('.anNiuZuo').click(function(){
    //     $('.wdFuli').hide();
    //     $('.cheDaibao').show();
    // });
    $("#siderBankCard").bind("click", function () {
        window.location.href = '/account/bank'
    });
    $('#earnings').bind('click', function () {
        linedatay2 = [];
        linedatax2 = [];
        $('#earnings').addClass('active');
        $('#investment').removeClass('active');
        $('#title').html('收益趋势图')
        //投资趋势
        $.ajax({
            type: "POST",
            url: "/account/incomeStat",
            data: {},
            dataType: 'json',
            async: true,

            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    linedatay2.push(data[i].incomeAmount);
                    linedatax2.push(data[i].incomeYear + '年' + data[i].incomeMonth + '月')
                }
                $('#line_chart').highcharts({
                    colors: ['#2cd4fe'],
                    title: {
                        text: ''
                    },
                    chart: {
                        type: 'line'
                    },
                    xAxis: {
                        title: {
                            text: ''
                        },
                        tickLength: 0,
                        categories: linedatax2,
                        labels: {
                            style: {
                                color: '#8f8f8f',
                                fontSize: '18px'
                            },
                            formatter: function () {
                                return this.value
                            }
                        }

                    },
                    yAxis: {
                        title: {
                            text: ''
                        },
                        gridLineWidth: 0,
                        lineColor: '#a5a5a5',
                        tickLength: 10,
                        tickColor: '#a5a5a5',
                        tickWidth: 1,
                        tickmarkPlacement: 'on',
                        startOnTick: false, // y轴坐标是否从某一刻度开始（这个设定与标题无关）
                        lineWidth: 1,
                        labels: {
                            formatter: function () {
                                return this.value;
                            },
                            style: {
                                color: '#8f8f8f',
                                fontSize: '18px'
                            }
                        },

                    },
                    plotOptions: {

                        line: {
                            dataLabels: {
                                enabled: true,
                                formatter: function () {
                                    return Highcharts.numberFormat(this.y, 2, ".", ",")
                                },

                                style: {
                                    color: '#7e7e7e',
                                    fontSize: '24px',
                                    fontWeight: 'normal'
                                }
                            },
                            enableMouseTracking: false
                        },

                        series: {
                            marker: {
                                symbol: "circle",
                                radius: 5
                            }
                        }

                    },
                    "series": [
                        {
                            "data": linedatay2
                        }

                    ],
                    legend: {
                        enabled: false
                    },
                    credits: {
                        enabled: false
                    },
                });
            },
            error: function () {

            }

        });
    })
    $('#investment').bind('click', function () {
        linedatax = [];
        linedatay = [];
        $('#earnings').removeClass('active');
        $('#investment').addClass('active');
        $('#title').html('投资趋势图')
        investment()
    })

    //投资趋势
    function investment() {
        $.ajax({
            type: "POST",
            url: "/account/monthlyStat",
            data: {},
            dataType: 'json',
            async: true,

            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    linedatay.push(data[i].investAmount);
                    linedatax.push(data[i].investYear + '年' + data[i].investMonth + '月')
                }

                $('#line_chart').highcharts({
                    colors: ['#2cd4fe'],
                    title: {
                        text: ''
                    },
                    chart: {
                        type: 'line'
                    },
                    xAxis: {
                        title: {
                            text: ''
                        },
                        tickLength: 0,
                        categories: linedatax,
                        labels: {
                            style: {
                                color: '#8f8f8f',
                                fontSize: '18px'
                            },
                            formatter: function () {
                                return this.value
                            }
                        }

                    },
                    yAxis: {
                        title: {
                            text: ''
                        },
                        gridLineWidth: 0,
                        lineColor: '#a5a5a5',
                        tickLength: 10,
                        tickColor: '#a5a5a5',
                        tickWidth: 1,
                        tickmarkPlacement: 'on',
                        startOnTick: false, // y轴坐标是否从某一刻度开始（这个设定与标题无关）
                        lineWidth: 1,
                        labels: {
                            formatter: function () {
                                if (this.value.lengrh < 5) {
                                    return this.value;
                                } else if (4 < this.value.lengrh < 9) {
                                    return this.value / 1000 + 'k';
                                } else if (this.value.length > 9) {
                                    return this.value / 1000000 + 'm';
                                }
                            },
                            style: {
                                color: '#8f8f8f',
                                fontSize: '18px'
                            }
                        },

                    },
                    plotOptions: {

                        line: {

                            dataLabels: {
                                enabled: true,
                                formatter: function () {
                                    return Highcharts.numberFormat(this.y, 2, ".", ",")
                                },

                                style: {
                                    color: '#7e7e7e',
                                    fontSize: '24px',
                                    fontWeight: 'normal'
                                }
                            },
                            enableMouseTracking: false
                        },

                        series: {
                            marker: {
                                symbol: "circle",
                                radius: 5
                            }
                        }

                    },
                    "series": [
                        {
                            "data": linedatay

                        }

                    ],
                    legend: {
                        enabled: false
                    },
                    credits: {
                        enabled: false
                    },
                });
            },
            error: function () {

            }

        });
    }

//总资产
    $.ajax({
        type: "POST",
        url: "/user/account",
        data: {},
        dataType: 'json',
        async: true,
        success: function (data) {
            $('.num').html(data.account.total);
            $('#totalAccount').html(data.account.total);
            var principal = parseFloat(data.account.wait) - parseFloat(data.incomeStat.waitIncome);
            var lockcash = parseFloat(data.account.usable) - parseFloat(data.account.cash);
            /*将取到的数据渲染到页面上*/
            $('.use_balance').html(threeNumber(data.account.cash.toString()) + '&nbsp;元');
            $('#total-assets').html(threeNumber(data.account.total.toString()) + '&nbsp;元');
            $('#total-assets1').html(threeNumber(data.account.frozen.toString()) + '&nbsp;元');
            $('#total-assets2').html(threeNumber(data.account.wait.toString()) + '&nbsp;元');
            // pieDate1.push(
            //     ['待收本金', Number(principal)],
            //     ['可用余额', Number(data.account.cash)],
            //     ['冻结金额', Number(data.account.frozen)],
            //     ['待收利息', Number(data.incomeStat.waitIncome)],
            //     ['锁定余额', Number(lockcash)]);
            //
            // for (var i = 0; i < pieDate1.length; i++) {
            //     if (pieDate1[i][1] != 0) {
            //         pieDate.push(pieDate1[i])
            //     }
            // }

            //
            // $('#pie_chart').highcharts({
            //     chart: {
            //         plotBackgroundColor: null,
            //         plotBorderWidth: null,
            //         plotShadow: false,
            //     },
            //     colors: [
            //         '#ff6666',
            //         '#55c5ff',
            //         '#ffda77',
            //         '#d668ff',
            //         '#d4d4d4'
            //     ],
            //     title: {
            //         text: ''
            //     },
            //     tooltip: {
            //         enabled: false
            //
            //     },
            //     plotOptions: {
            //         pie: {
            //             allowPointSelect: true,
            //             size: '270px',
            //             innerSize: '208px',
            //             showInLegend: true,
            //             cursor: 'pointer',
            //             borderWidth: 0,
            //             dataLabels: {
            //                 enabled: true,
            //                 formatter: function () {
            //                     return '<p>' + Highcharts.numberFormat(this.y, 2, ".", ",") + '</p>' + '<br/>' + this.point.name + '';
            //                 },
            //                 style: {
            //                     color: '#767676',
            //                     fontSize: '18px',
            //                     fontWeight: 'normal'
            //                 }
            //             }
            //         }
            //     },
            //     legend: {
            //         enabled: false,
            //         useHTML: false,
            //     },
            //     credits: {
            //         enabled: false
            //     },
            //     series: [{
            //         type: 'pie',
            //         name: '',
            //         data:pieDate
            //
            //     }]
            // });
            //
            // if(data.account.total==0){
            //     $('#pie_chart').html('<img src="/img/indexzanwushuju.png" style="margin-left: 115px;margin-top: 27px;" />');
            //     $('.center_text').html('')
            // }
        },
        error: function () {

        },

    });


    var oDiv = document.getElementById('div1');
    var oNowTime = document.getElementById('nowTime');
    var aTd = oDiv.getElementsByTagName('td');
    var aNowSpan = oNowTime.getElementsByTagName('span');
    var oDate = new Date();
    var bottomTable = document.getElementById('bottomTable');
    var detailItem = document.getElementById('detailItem');
    var nowDay = document.getElementById('nowDay');
    var clickDateArr = [];
    var dayNum = 0;//当月天数

    showDate(oNowTime, oDate.getFullYear(), oDate.getMonth() + 1);
    hideLastTr();
    showBtn();
    var _today = oDate.getFullYear() + '-' + (oDate.getMonth() + 1) + '-' + oDate.getDate()
    detailItem.innerHTML = "" + _today;//右侧投资记录时间
    // nowDay.innerHTML="" + (oDate.getMonth() + 1);//当日

    investRecord(_today);
    function showDate(obj, year, month, bBtn) {
        var oDate = new Date();
        var lastMonthdayNum = 0;
        if (!obj.bBtn) {
            obj.oTitle = document.createElement('div');
            obj.oTitle.className = 'title';
            obj.appendChild(obj.oTitle);

            var oTable = document.createElement('table');
            var oThead = document.createElement('tHead');
            var oTr = document.createElement('tr');
            var arr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'];
            for (var i = 0; i < 7; i++) {
                var oTh = document.createElement('th');
                oTh.innerHTML = arr[i];
                oTr.appendChild(oTh);
            }
            oThead.appendChild(oTr);
            oTable.appendChild(oThead);

            var oTbody = document.createElement('tBody');
            for (var i = 0; i < 6; i++) {
                var oTr = document.createElement('tr');
                for (var j = 0; j < 7; j++) {
                    var oTd = document.createElement('td');
                    oTr.appendChild(oTd);
                }
                oTbody.appendChild(oTr);
            }
            oTable.appendChild(oTbody);
            obj.appendChild(oTable);
            obj.bBtn = true;
        }

        obj.oTitle.innerHTML = ( '<div><span class="leftbutton"></span><span>' + year + '</span>年<span>' + month + '</span>月<span class="rightbutton"></span></div>');

        var aTd = obj.getElementsByTagName('td');
        for (var i = 0; i < aTd.length; i++) {
            aTd[i].innerHTML = '';
        }

        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            dayNum = 31;
        }
        else if (month == 4 || month == 6 || month == 9 || month == 11) {
            dayNum = 30;
        }
        else if (month == 2 && isLeapYear(year)) {
            dayNum = 29;
        }
        else {
            dayNum = 28;
        }

        if (month == 5 || month == 7 || month == 10 || month == 12) {
            lastMonthdayNum = 30;
        }
        else if (month == 2 || month == 1 || month == 4 || month == 6 || month == 8 || month == 9 || month == 11) {
            lastMonthdayNum = 31;
        }
        else if (month == 3 && isLeapYear(year)) {
            lastMonthdayNum = 29;
        }
        else {
            lastMonthdayNum = 28;
        }

        oDate.setFullYear(year);//设置年份
        oDate.setMonth(month - 1);//设置月份
        oDate.setDate(1);//设置1号

        for (var l = 0; l < 7; l++) {//上个月日期颜色恢复
            aTd[l].style.color = '';
        }

        //---------------------下个月数字----------------------------
        for (var ll = 28; ll < 41; ll++) {//下个月日期颜色恢复
            aTd[ll].style.color = '';
        }

        if (oDate.getDay() == 0) {//本月首日星期天判断
            var monthNum = dayNum + 6
        } else {
            var monthNum = dayNum + oDate.getDay() - 1
        }
        var nextMonth = 42 - monthNum //下个月出现天数

        for (var ff = 0; ff < nextMonth; ff++) {//下个月数字和颜色
            aTd[ff + monthNum].innerHTML = ff + 1;
            aTd[ff + monthNum].style.color = '#e8e8e8';
        }
        //---------------------下个月数字end----------------------------
        switch (oDate.getDay()) {//1号星期几
            case 0:
                for (var i = 0; i < dayNum; i++) {
                    aTd[i + 6].innerHTML = i + 1;
                }
                for (var k = 0; k < 6; k++) {
                    aTd[k].style.color = '#e8e8e8';
                }
                var leftdayNum0 = lastMonthdayNum - 5;
                for (var j = 0; j < 6; j++) {
                    aTd[j].innerHTML = leftdayNum0++;
//                        aTd[j].style.color='#97929c';
                }

                break;
            case 1:
                for (var i = 0; i < dayNum; i++) {
                    aTd[i].innerHTML = i + 1;
                }
                // for(var k=0;k<4;k++){
                //     aTd[k].style.color='#e8e8e8';
                // }
                break;
            case 2:
                for (var i = 0; i < dayNum; i++) {
                    aTd[i + 1].innerHTML = i + 1;
                }
                for (var k = 0; k < 1; k++) {
                    aTd[k].style.color = '#e8e8e8';
                }
                aTd[0].innerHTML = lastMonthdayNum;
//                    aTd[0].style.color='#97929c';

                break;
            case 3:
                for (var i = 0; i < dayNum; i++) {
                    aTd[i + 2].innerHTML = i + 1;
                }
                for (var k = 0; k < 2; k++) {
                    aTd[k].style.color = '#e8e8e8';
                }
                aTd[0].innerHTML = lastMonthdayNum - 1;
                aTd[1].innerHTML = lastMonthdayNum;
//                    aTd[0].style.color=aTd[1].style.color='#97929c';
                break;
            case 4:
                for (var i = 0; i < dayNum; i++) {
                    aTd[i + 3].innerHTML = i + 1;
                }
                for (var k = 0; k < 3; k++) {
                    aTd[k].style.color = '#e8e8e8';
                }
                aTd[0].innerHTML = lastMonthdayNum - 2;
                aTd[1].innerHTML = lastMonthdayNum - 1;
                aTd[2].innerHTML = lastMonthdayNum;
//                    aTd[0].style.color=aTd[1].style.color=aTd[2].style.color='#97929c';
                break;
            case 5:
                for (var i = 0; i < dayNum; i++) {
                    aTd[i + 4].innerHTML = i + 1;
                }
                for (var k = 0; k < 4; k++) {
                    aTd[k].style.color = '#e8e8e8';
                }
                var leftdayNum5 = lastMonthdayNum - 3;
                for (var j = 0; j < 4; j++) {
                    aTd[j].innerHTML = leftdayNum5++;
//                        aTd[j].style.color='#97929c';
                }
                break;
            case 6:
                for (var i = 0; i < dayNum; i++) {
                    aTd[i + 5].innerHTML = i + 1;
                }
                for (var k = 0; k < 5; k++) {
                    aTd[k].style.color = '#e8e8e8';
                }
                var leftdayNum6 = lastMonthdayNum - 4;
                for (var j = 0; j < 5; j++) {
                    aTd[j].innerHTML = leftdayNum6++;
//                        aTd[j].style.color='#97929c';
                }
                break;

        }

        var dateString = year + '-' + month;
        getShowDate(dateString)
    }

    function getShowDate(date) {
        $.ajax({
            type: 'POST',
            url: "/user/calendarDisplayList",
            dataType: 'json',
            data: {date: date},
            success: function (data) {
                var getData = data;
                var investListDate = [];
                var repayListDate = [];
                var investRepayDate = [];
                if (getData.data) {
                    for (var getDate in getData.data) {
                        var _date = getDate.substring(0, 4) + "/" + getDate.substring(4, 6) + "/" + getDate.substring(6, 8) + " 08:00:00";
                        if (getData.data[getDate] == "INVEST") {
                            investListDate.push((new Date(_date)).getTime());
                        } else if (getData.data[getDate] == "COLLECT") {
                            repayListDate.push((new Date(_date)).getTime());
                        } else if (getData.data[getDate] == "COLLECT,INVEST") {
                            investRepayDate.push((new Date(_date)).getTime());
                        }
                    }
                }
                var newd = [];
                var newE = [];

                for (var k = 0; k < investListDate.length; k++) {
                    var d = new Date();
                    d.setTime(investListDate[k]);
                    newd.push(d);
                    showCircle(d, 'invest')
                }


                for (var l = 0; l < repayListDate.length; l++) {
                    var e = new Date();
                    e.setTime(repayListDate[l]);
                    newE.push(e);
                    showCircle(e, 'money')
                }

                for (var dd = 0; dd < investRepayDate.length; dd++) {
                    var f = new Date();
                    f.setTime(investRepayDate[dd]);
                    newE.push(f);
                    showCircle(f, 'money-invest')
                }

                //
                // for (var dd = 0; dd < newd.length; dd++) {
                //     for (var ee = 0; ee < newE.length; ee++) {
                //         if (newd[dd].getFullYear() == newE[ee].getFullYear() && newd[dd].getMonth() == newE[ee].getMonth() && newd[dd].getDate() == newE[ee].getDate()) {
                //             showCircle(newd[dd], 'money-invest')
                //
                //         }
                //
                //     }
                // }


                var newtd = document.getElementsByTagName('td');
                for (var i = 0; i < newtd.length; i++) {
                    newtd[i].onclick = null;
                }


                getShowList();
            },
            error: function (data) {

            }

        });
    }

    function getShowList() {
        clickDateArr = [];
        for (var ii = 0; ii < aTd.length; ii++) {
            if (aTd[ii].className.indexOf('invest') != -1 || aTd[ii].className.indexOf('money') != -1 || aTd[ii].className.indexOf('money-invest') != -1) {
                clickDateArr.push(aTd[ii])
            }

        }
        for (var jj = 0; jj < clickDateArr.length; jj++) {

            clickDateArr[jj].onclick = function () {
                for (var jjj = 0; jjj < aTd.length; jjj++) {
                    // removeClass(aTd[jjj], 'today1');
                    // removeClass(aTd[jjj], 'today');
                }
                // addClass(this, 'today1');
                detailItem.innerHTML = "" + aNowSpan[1].innerHTML + "－" + aNowSpan[2].innerHTML + "－" + this.innerHTML;
                var viewDate = aNowSpan[1].innerHTML + '-' + aNowSpan[2].innerHTML + '-' + this.innerHTML;

                // nowDay.innerHTML=aNowSpan[2].innerHTML;
                // pg.paging(1, 6, "/user/calendarList", 'bottomTable', 'bottomTableTemp',{viewDate:viewDate} );
                // paging: function(page, pagesize, url, domid,template, paramdata,) {
                investRecord(viewDate);

            }
        }

        if (clickDateArr.length > 0) {
            for (var i = 0; i < clickDateArr.length; i++) {
                if (clickDateArr[i].innerHTML == oDate.getDate() && aNowSpan[1].innerHTML == oDate.getFullYear() && aNowSpan[2].innerHTML == oDate.getMonth() + 1) {
                    clickDateArr[i].click()
                }
            }
        }

        showCircle(oDate, 'today');


    }

    //投资记录
    function investRecord(viewDate){
        $('#pages').html('')
        $.ajax({
            type: "post",
            url: '/user/calendarList',
            data: {viewDate: viewDate},
            async: true,
            dataType: "json",
            success: function (data) {
                layer.closeAll('loading');
                if (data.list && data.list.length != 0) {
                    var bottomTable = '';
                    for (var i = 0; i < data.list.length; i++) {
                        if (data.list[i].itemName && data.list[i].itemName.length > 4) {
                            data.list[i].itemName = data.list[i].itemName.substring(0, 4) + '...';
                        }
                        var status=data.list[i].itemStatus;
                        if(data.list[i].type == "投资"){
                            if(status == 0||status == 1||status == 3){
                                status = "投资成功";
                            }else if(status == -1){
                                status = "投资中";
                            }else if(status == 2){
                                status = "投资失败";
                            }
                        }else if(data.list[i].type == "还款"){
                            if(status == 0){
                                status = "还款中";
                            }else if(status == 1){
                                status = "还款成功";
                            }
                        }
                        if (data.list[i].debtJumpId) {
                            //债转
                            var gg = '/debt/getDebtDetail/' + data.list[i].debtJumpId + '?' + data.list[i].debtJumpId
                            if (data.list[i].contractsUrl) {
                                var ggImg = data.list[i].contractsUrl
                                bottomTable = bottomTable +
                                    "<tr><td class='imgTd'>项&#12288;&#12288;目：" +
                                    '<a href="' + gg + '" style="color:#5e5d5d">' + data.list[i].itemName + '</a>' +
                                    "<a href='" + ggImg + "'><img" +
                                    " src='/img/contract.png'/>" +

                                    '</a></td></tr><tr><td>'
                                    +
                                    "状&#12288;&#12288;态：" + status + "</td></tr><tr><td>待收本金：" +
                                    data.list[i].principal + "</td></tr><tr class='moneymove'><td>待收利息：" +
                                    data.list[i].interest + "</td></tr>"
                            } else {
                                //没有合同
                                bottomTable = bottomTable +
                                    "<tr><td class='imgTd'>项&#12288;&#12288;目：" +
                                    '<a href="' + gg + '" style="color:#5e5d5d">' + data.list[i].name + '</a></td></tr><tr><td>'
                                    +
                                    "状&#12288;&#12288;态：" + status + "</td></tr><tr><td>待收本金：" +
                                    data.list[i].principal + "</td></tr><tr class='moneymove'><td>待收利息：" +
                                    data.list[i].interest + "</td></tr>"

                            }

                        } else {
                            //不是债转
                            var hh = '/item/details/' + data.list[i].itemId + '?' + data.list[i].itemId
                            if (data.list[i].contractsUrl) {
                                //有合同
                                var ggImg = data.list[i].contractsUrl
                                bottomTable = bottomTable +
                                    "<tr><td class='imgTd'>项&#12288;&#12288;目：" +
                                    '<a href="' + hh + '" style="color:#5e5d5d">' + data.list[i].itemName + '</a>' +
                                    "<a href='" + ggImg + "'><img" +
                                    " src='/img/contract.png'/>" +
                                    '</a></td></tr><tr><td>' +
                                    "状&#12288;&#12288;态：" + status + "</td></tr><tr><td>待收本金：" +
                                    data.list[i].principal + "</td></tr><tr class='moneymove'><td>待收利息：" +
                                    data.list[i].interest + "</td></tr>"
                            } else {
                                //没有合同
                                bottomTable = bottomTable +
                                    "<tr><td class='imgTd'>项&#12288;&#12288;目：" +
                                    '<a href="' + hh + '" style="color:#5e5d5d">' + data.list[i].itemName + '</a></td></tr><tr><td>'
                                    +
                                    "状&#12288;&#12288;态：" + status + "</td></tr><tr><td>待收本金：" +
                                    data.list[i].principal + "</td></tr><tr class='moneymove'><td>待收利息：" +
                                    data.list[i].interest + "</td></tr>"
                            }


                        }
                        /* bottomTable = bottomTable +
                         "<tr><td class='imgTd'>项目:&nbsp&nbsp&nbsp" +
                         data.list[i].itemName +
                         "<a href=''><img src='/img/contract.png'/></a></td></tr><tr><td>" +
                         "状态:&nbsp&nbsp&nbsp" + data.list[i].type + "</td></tr><tr><td>金额:&nbsp&nbsp&nbsp" +
                         data.list[i].amount + "</td></tr><tr></tr>"*/
                    }
                    $('#bottomTable').html(bottomTable)
                } else {
                    $('#bottomTable').html("");
                    $('#pages').html("<div class='no_money'><img src='/img/nomoney.png' class='nomoney'><a href='/item/investmentList?0?1'>快去投资吧...</a></div>");
                }
            },
            error: function (e) {
                layer.msg("服务器通讯失败", {
                    icon: 5
                });
                layer.closeAll('loading');
            }
        });
    }

    function hasClass(obj, cls) {
        return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
    }

    function addClass(obj, cls) {
        if (!hasClass(obj, cls))
            obj.className += " " + cls;
    }

    function removeClass(obj, cls) {
        if (hasClass(obj, cls)) {
            var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
            obj.className = obj.className.replace(reg, ' ');
        }
    }

    function showCircle(date, className) {
        var result = [];

        var index = 0;
        for (var i = 0; i < aTd.length; i++) {
            if (aTd[i].innerHTML == 1) {
                index = i;
                break;
            }
        }
        for (var j = index; j < dayNum + index; j++)
            if (aTd[j].innerHTML != '') {
                result.push(aTd[j]);
            }

        if (aNowSpan[1].innerHTML == date.getFullYear() && aNowSpan[2].innerHTML == date.getMonth() + 1) {
            for (var k = 0; k < result.length; k++) {
                if (date.getDate() == result[k].innerHTML) {
                    addClass(result[k], className)
                }
            }
        }

    }

    function isLeapYear(year) {
        if (year % 4 == 0 && year % 100 != 0) {
            return true;
        }
        else {
            if (year % 400 == 0) {
                return true;
            }
            else {
                return false;
            }
        }
    }

    function showBtn() {
        // detailItem.innerHTML = '';
        // bottomTable.innerHTML = '';
        var Month = parseInt(aNowSpan[2].innerHTML);
        var Year = parseInt(aNowSpan[1].innerHTML);


        aNowSpan[0].onclick = function () {

            if (Month == 10 && Year == 2015) {
                this.onclick = null;
                return
            }


            for (var i = 0; i < aTd.length; i++) {
                aTd[i].className = '';

            }

            if (Month == 1) {
                showDate(oNowTime, Year - 1, 12);
            }
            else {
                showDate(oNowTime, Year, Month - 1);
            }


            showBtn();
            hideLastTr();
            //getShowDate();
        };

        aNowSpan[3].onclick = function () {


            for (var i = 0; i < aTd.length; i++) {
                aTd[i].className = '';

            }
            if (Month == 12) {
                showDate(oNowTime, Year + 1, 1);
            }
            else {
                showDate(oNowTime, Year, Month + 1);
            }

            showBtn();
            hideLastTr();
            //getShowDate();
        };

    }

    function hideLastTr() {
        var bBtn = true;

        for (var i = 35; i < 42; i++) {
            if (aTd[i].innerHTML != '') {
                bBtn = false;
            }
        }

        if (bBtn) {
            for (var i = 35; i < 42; i++) {
                aTd[i].parentNode.style.display = 'none';
            }
        }
        else {
            for (var i = 35; i < 42; i++) {
                aTd[i].parentNode.style.display = '';
            }
        }

    }

    function listUp() {
        // var _top=document.getElementById('headerMiddle').offsetHeight
        // console.log(_top)
        // setTimeout(listUp,5000)
        var headerMiddle = document.getElementById('headerMiddle');
        var tableTop = document.getElementById('tableTop');
        var tableBm = document.getElementById('tableBm');
        tableBm.innerHTML = tableTop.innerHTML;

    }

    listUp()

    var speed = 50;

    function Marquee() {
        // console.log(tableBm.offsetTop+'-'+headerMiddle.scrollTop);
        if (tableBm.offsetTop - headerMiddle.scrollTop <= 969) {
            headerMiddle.scrollTop -= tableTop.offsetHeight;
        } else {
            headerMiddle.scrollTop++;
        }
    }

    var MyMar = setInterval(Marquee, speed);

    headerMiddle.onmouseover = function () {
        clearInterval(MyMar);
    }

    headerMiddle.onmouseout = function () {
        MyMar = setInterval(Marquee, speed);
    }


});
